// index page
// ============

define(['require', 'zepto', 'sui', 'zeptoFx', 'zeptoTouch', 'submitForm', 'raty'], function(require, JST) {
  return {
    init: function(data) {
      this.grade = data.grade;
      this.initPage();
      this.initSubmit();
    },
    
    initPage: function() {
        var that = this;
        
    	$(function() {
    	    $.fn.raty.defaults.path = 'lib/img';
    	    $('#grade-demo').raty({
    	    	readOnly: that.grade == 0 ? false : true,
    	        number: 10, //多少个星星设置
    	        score: that.grade,
    	        targetType: 'hint', //类型选择，number是数字值，hint，是设置的数组值
    	        path: window.__CTX__.resource + "/js/component/raty/images",
    	        size: 24,
    	        cancel: false,
    	        targetKeep: true,
    	        targetText: '请选择评分',
    	        click: function(score, evt) {
    	            //alert('ID: ' + $(this).attr('id') + "\nscore: " + score + "\nevent: " + evt.type);
    	        }
    	    });
    	});
    },
    
    initSubmit: function() {
      var that = this
      
      $(".save-button").on("click", function() {
        $("[type='submit']").trigger("click")
      });
      
      $("form").submitform({
        beforeSubmit: function(el) {
            var grade = $("input[name='score']").val();
            
            if(!grade || grade == 0) {
              $.toast("请评分");
              return false;
            }
            
            return true;
        },
        successUrl: $(".fs-header-small a").attr('href')
      })
      
    }
  }
})